#include <pthread.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>

void* start_routine(void * arg){
    srand(time(NULL));
    int num = rand() % 100;
    
    printf("in sub thread : %d\n",num);

    int * p = (int*)malloc(sizeof(int)); 
    *p = num;
    pthread_exit((void*)p);
}


int main()
{
    pthread_t pthid1,pthid2,pthid3;
    pthread_create(&pthid1,NULL,start_routine,NULL);
    pthread_create(&pthid2,NULL,start_routine,NULL);
    pthread_create(&pthid3,NULL,start_routine,NULL);
    int *ret1 = NULL;
    int *ret2 = NULL;
    int *ret3 = NULL;
    pthread_join(pthid1,(void**)&ret1);
    pthread_join(pthid2,(void**)&ret2);
    pthread_join(pthid3,(void**)&ret3);

    printf("*ret1 = %d \n",*ret1);
    printf("*ret2 = %d \n",*ret2);
    printf("*ret3 = %d \n",*ret3);

    return 0;
}

